package cn.yedong.basic.service.impl;
/**
 * 业务实现类：部门
 */

import cn.yedong.basic.mapper.BaseMapper;
import cn.yedong.basic.query.BaseQuery;
import cn.yedong.basic.service.IBaseService;
import cn.yedong.basic.util.QueryResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

//该注解可以被所有service实现类继承
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    @Transactional
    public void add(T t) {
        baseMapper.add(t);
    }

    @Override
    @Transactional
    public void del(Long id) {
        baseMapper.del(id);
    }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    public T loadById(Long id) {
        return baseMapper.loadById(id);
    }

    @Override
    public List<T> loadAll() {
        return baseMapper.loadAll();
    }

    public QueryResult<T> pageQuery(BaseQuery baseQuery) {
        //查询总数量
        Integer count = baseMapper.queryCount(baseQuery);
        //如果总数量为0，则不进行分页数据查询
        if(count==0){
            return new QueryResult<>();
        }
        //查询分页显示数据
        List<T> datas = baseMapper.queryData(baseQuery);
        return new QueryResult<>(count,datas);
    }

    @Override
    public void patchDel(List<Long> ids) {
        baseMapper.patchDel(ids);
    }

    
}
